#!/usr/bin/env python3
import os
import configparser
import sys

class config:
    def __init__(self, scan_directory = "~", literatures_DB_dirctory = "~/.local/share/literatures_DB_dirctory/"):
        configPath = os.path.expanduser("~/.config/literaturetool/config.cfg")
        if os.path.exists(configPath) and os.path.isfile(configPath):
            config = configparser.ConfigParser()
            config.read(configPath, "utf-8")
            scan = config.get("core", "scan_directory")
            DB = config.get("core", "literatures_DB_directory")
            self.scan_directory = os.path.expanduser(scan)
            self.literatures_DB_directory = os.path.expanduser(DB)
        else:
            self.scan_directory = os.path.expanduser(scan_directory)
            self.literatures_DB_directory = os.path.expanduser(literatures_DB_dirctory)
        if not (os.path.exists(self.scan_directory) and os.path.isdir(self.scan_directory)):
            print("the scan directory ", self.scan_directory, " is not exists.")
            print("you should correct the config: ", configPath)
            sys.exit(1)
        if not (os.path.exists(self.literatures_DB_directory) and os.path.isdir(self.literatures_DB_directory)):
            print("the DB directory ", self.literatures_DB_directory, " is not exists.")
            print("you should correct the config: ", configPath)
            sys.exit(1)

def test():
    a = config()
    print("scan_dirctory: ", a.scan_directory)
    print("literatures_DB_dirctory: ", a.literatures_DB_directory)


if __name__ == "__main__":
    test()
